package model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Class for manipulation of a simple match between two players. 
 * Date, lenght, score, winner and loser as main attributes
 *  
 * @author Andre Melo
 * @author Marcus Leite 
 * @author Sergio Danilo
 */
@Entity
@Table(name = "MATCHES")
public class Match {

	//Attributes
	//Columns for Data Base manipulation
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "MATCH_DATE", nullable = false)
	private Date date;
	
	@Column(name = "LENGHT", nullable = true)
	private Integer lenght;
	
	@Column(name = "SCORE", nullable = true)
	private Integer score;
	
	@Column(name = "LONG_RUN_WIN", nullable = true)
	private Integer longestRunForWinner;
	
	@Column(name = "LONG_RUN_LOS", nullable = true)
	private Integer longestRunForLoser;
	
	@ManyToOne
	private User winner;
	
	@ManyToOne
	private User loser;
	
	@ManyToOne
	private League league;
	
	@Column(name = "MATCH_INDEX", nullable = true)
	private Integer matchIndex;
	
	/**
	 * Simple match's constructor
	 */
	public Match(){}
	
	/**
	 * Match's constructor
	 * 
	 * @param league The league that the match is included
	 * @param date The match's date
	 * @param winner The winner player
	 * @param loser The loser player
	 */
	public Match(League league, Date date, User winner, 
			User loser) {
		this.league = league;
		this.date = date;
		this.winner = winner;
		this.loser = loser;
	}

	/**
	 * Match's constructor
	 * 
	 * @param league The league that the match is included
	 * @param date The match's date
	 * @param winner The winner player
	 * @param loser The loser player
	 * @param length The match's length
	 * @param score The match's score
	 * @param longestRunForWinner The longest run for winner of the match 
	 * @param longestRunForLoser The longest run for loser of the match
	 */
	public Match(League league, Date date, User winner, User loser,
			Integer length, Integer score, Integer longestRunForWinner,
			Integer longestRunForLoser) {
		this.league = league;
		this.date = date;
		this.winner = winner;
		this.loser = loser;
		this.lenght = length;
		this.score = score;
		this.longestRunForWinner = longestRunForWinner;
		this.longestRunForLoser = longestRunForLoser;
	}

	/**
	 * Get the date of the match
	 * @return A date format
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * Set the date of the match
	 * @param date The new date
	 */
	public void setDate(Date date) {
		this.date = date;
	}
	
	/**
	 * Get the ID of the match for Data Base manipulation
	 * @return The ID for DB manipulation
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Set the ID of the match
	 * @param id The new ID
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Get the league that the match is included
	 * @return The current league 
	 */
	public League getLeague() {
		return league;
	}

	/**
	 * Set the league that the match is included
	 * @param league The new league
	 */
	public void setLeague(League league) {
		this.league = league;
	}

	/**
	 * Get the length of the match
	 * @return A current length
	 */
	public Integer getLenght() {
		return lenght;
	}

	/**
	 * Set the length of the match
	 * @param id The new length of the match
	 */
	public void setLenght(Integer lenght) {
		this.lenght = lenght;
	}

	/**
	 * Get the score of the match
	 * @return A current score
	 */
	public Integer getScore() {
		return score;
	}

	/**
	 * Set the score of the match
	 * @param id The new score of the match
	 */
	public void setScore(Integer score) {
		this.score = score;
	}

	/**
	 * Get the longest run for winner of the match 
	 * @return A current longest run for winner
	 */
	public Integer getLongestRunForWinner() {
		return longestRunForWinner;
	}

	/**
	 * Set the longest run for winner of the match
	 * @param id The new longest run for winner of the match 
	 */
	public void setLongestRunForWinner(Integer longestRunForWinner) {
		this.longestRunForWinner = longestRunForWinner;
	}

	/**
	 * Get the longest run for loser of the match 
	 * @return A current longest run for loser
	 */
	public Integer getLongestRunForLoser() {
		return longestRunForLoser;
	}

	/**
	 * Set the longest run for loser of the match
	 * @param id The new longest run for loser of the match 
	 */
	public void setLongestRunForLoser(Integer longestRunForLoser) {
		this.longestRunForLoser = longestRunForLoser;
	}

	/**
	 * Get the winner of the match
	 * @return A current winner
	 */
	public User getWinner() {
		return winner;
	}

	/**
	 * Set the winner of the match
	 * @param id The new winner of the match
	 */
	public void setWinner(User winner) {
		this.winner = winner;
	}

	/**
	 * Get the loser of the match
	 * @return A current loser
	 */
	public User getLoser() {
		return loser;
	}

	/**
	 * Set the loser of the match
	 * @param id The new loser of the match
	 */
	public void setLoser(User loser) {
		this.loser = loser;
	}

	/**
	 * Get the index of the match 
	 * @return A current index
	 */
	public Integer getMatchIndex() {
		return matchIndex;
	}

	/**
	 * Set the index of the match 
	 * @param id The new match index
	 */
	public void setMatchIndex(Integer matchIndex) {
		this.matchIndex = matchIndex;
	}
}
